package com.wang.cloud.common.core.exception;


import com.wang.cloud.common.core.api.ApiResultCode;

import java.util.StringJoiner;

/**
 * 业务异常
 *
 * @author dcb
 */
public class ServiceException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误提示
     */
    private final String message;


    public ServiceException(String message) {
        this.message = message;
        this.code = ApiResultCode.HTTP_INTERNAL_ERROR;
    }

    public ServiceException(String message, Integer code) {
        this.message = message;
        this.code = code;
    }

    public ServiceException(String message, Throwable e) {
        super(message, e);
        this.message = message;
        this.code = ApiResultCode.HTTP_INTERNAL_ERROR;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public Integer getCode() {
        return code;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", ServiceException.class.getSimpleName() + "[", "]")
                .add("code=" + code)
                .add("message='" + message + "'")
                .toString();
    }
}
